import {Component, OnInit, ViewChild} from '@angular/core';

@Component({
    selector: 'app-codemirror',
    templateUrl: './codemirror.component.html',
    styleUrls: ['./codemirror.component.less']
})
export class CodemirrorComponent implements OnInit {

    hook: CodeMirror
    value = 'select * from opm_sql;'
    text: string
    isReadonly = false
    @ViewChild('codemirror', {static: true}) textarea

    constructor() {
    }

    ngOnInit(): void {
        this.textarea.nativeElement.value = this.value
        this.hook = window.CodeMirror.fromTextArea(this.textarea.nativeElement, {
            theme: 'darcula',
            lineNumbers: true,
            mode: 'sql',
            styleActiveLine: true,
            scrollbarStyle: 'simple'
        });
    }

    changeValue() {
        this.hook.setValue('select * from opm_sql_update')
    }

    getText() {
        this.text = this.hook.getValue()
    }

    readonly() {
        this.isReadonly = !this.isReadonly;
        this.hook.setOption('readOnly', this.isReadonly)
        console.log(this.isReadonly)
    }

}
